var swiper = new Swiper('#indexpage .swiper-container', {
	nextButton: '.swiper-button-next',
	prevButton: '.swiper-button-prev',
	slidesPerView: 7,
        slidesPerGroup : 4,
	paginationClickable: true,
	spaceBetween: 30,
	loop: true
});

$('.has-account').on('click', function() {
	$('.jl-no').css('display', 'none');
	$('.jl-yes').css('display', 'block');
})
$('.no-account').on('click', function() {
	$('.jl-no').css('display', 'block');
	$('.jl-yes').css('display', 'none');
})
if($('#flag_status').val()==1){
	$('.mm-mask').removeClass('mm-hidden')
    $('.jl-no').css('display', 'block');
    $('.jl-yes').css('display', 'none');
    $('.login-lq').css('display', 'none');
}else if($('#flag_status').val()==3){
    $('.mm-mask').removeClass('mm-hidden')
    $('.jl-no').css('display', 'none');
    $('.jl-yes').css('display', 'none');
    $('.login-lq').css('display', 'block');
}


$('.jl-box i').on('click', function() {
	$('.mm-mask').fadeOut(400, function() {
		$('.mm-mask').removeAttr('style')
		$('.mm-mask').addClass('mm-hidden')
	})
})

$('.mm-mask').on('click', '#jl-colse', function() {
	$('.mm-mask').fadeOut(400, function() {
		$('.mm-mask').removeAttr('style')
		$('.mm-mask').addClass('mm-hidden')
       
	})
})
$('.mm-mask').on('click', '#jl-colse1', function() {
	$('.mm-mask').fadeOut(400, function() {
		$('.mm-mask').removeAttr('style')
		$('.mm-mask').addClass('mm-hidden')
        window.location.reload();
	})
})

var re = /^(13[0-9]{9})|(15[0-9]{9})|(17[0-9]{9})|(18[0-9]{9})$/;
var resu = '';
$('.jl-no-code').on('focus', function() {
	if(!re.test($('.jl-p-n').val()) || $('.jl-p-n').val() == '') {
		layer.msg('手机号格式错误');

	}
})
$('.getCode').on('click', function() {
	if(!re.test($('.jl-p-n').val()) || $('.jl-p-n').val() == '') {
		layer.msg('手机号格式错误');

	} else {
        $.ajax({
            type: 'post',
            url: "/user/sendRegCode",
            data: {
                mobile:$('.jl-p-n').val(),
                is_check:1,
                type:1,
            },
            async: true,
            dataType: "json",
            success: function(msg) {
                if(msg.status==1)
                {
                    // layer.msg("发送成功");
                    common.getidentCode('.getCode', 60)
                }else{
                    layer.msg(msg.text);
                }

            },
            error: function(a, b, c) {
                layer.msg("请求错误");
            }
        })
	}
});

$('.jl-lq').on('click', function() {
    var mobile = $('.jl-p-n').val();
    var password = $('.set-jlmm').val();
    var code     = $('.jl-no-code').val();
    if(!re.test(mobile) || mobile == ''){
        layer.msg('手机号格式错误');
        return false;
    }
    if(code == ''){
        layer.msg('验证码不能为空');
        return false;
    }
    if (password == ''){
        layer.msg('密码不能为空');
        return false;
    }
    if (password.length < 6 || password.length > 20) {
        layer.msg('密码长度需要在6-20位之间');
        return false;
    }
    $.ajax({
        type: 'post',
        url: '/user/couponReg',
        data: {'mobile':mobile,
			'password':password,
			'code':code,
		},
        async: true,
        dataType: "json",
        success: function(msg) {
            if(msg.status==2)
            {
                layer.msg(msg.text);
                return false;

            }else{

                $('.jl-box').css('display', 'none');
                $('.jlerror').html(msg.text);
                $('.receive-suss').css('display', 'block');
            }

        },
        error: function(a, b, c) {
            layer.msg("请求错误");
        }
    })


})

$('#jl-yes').on('click', function() {
    var mobile = $('#jlmobile').val();
    var password = $('#jlpassword').val();
    if(mobile == '') {
        layer.msg('用户名不能为空');
        return false;
    }
    if (password == ''){
        layer.msg('密码不能为空');
        return false;
    }

    $.ajax({
        type: 'post',
        url: '/user/couponLogin',
        data: {'mobile':mobile,
            'password':password,
        },
        async: true,
        dataType: "json",
        success: function(msg) {
            if(msg.status==2)
            {
                layer.msg(msg.text);
                return false;
            }else{

                $('.jl-box').css('display', 'none');
                $('.jlerror').html(msg.text);
                $('.receive-suss').css('display', 'block');
            }

        },
        error: function(a, b, c) {
            layer.msg("请求错误");
        }
    })


})
$('#jl_ling').on('click', function() {
    $.ajax({
        type: 'post',
        url: '/user/couponReceive',
        data: {},
        dataType: "json",
        success: function(msg) {
            if(msg.status==2)
            {
                layer.msg(msg.text);
                return false;

            }else if(msg.status==-1){
                $('.jl-no').css('display', 'block');
                $('.jl-yes').css('display', 'none');
                $('.login-lq').css('display', 'none');
                $('.receive-suss').css('display', 'none');
            }else{

                $('.jl-box').css('display', 'none');
                $('.jlerror').html(msg.text);
                $('.receive-suss').css('display', 'block');
            }

        },
        error: function(a, b, c) {
            layer.msg("请求错误");
        }
    })
})